package cc.fozone.note.view;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.layout.FlowPane;
import cc.fozone.note.configuration.IConfiguration;

public class MenuView extends FlowPane {
	private IConfiguration<String,String> configuration;
	
	private Button create;
	private Button skin;
	private Button about;
	
	private String createTitle = "新建文本";
	private String skinTitle = "皮肤";
	private String aboutTitle = "关于";
	
	private String styleClass = "menus";
	private String createStyleClass = "menu-create";
	private String skinStyleClass = "menu-skin";
	private String aboutStyleClass = "menu-about";
	
	public MenuView(IConfiguration<String,String> configuration) {
		// TODO Auto-generated constructor stub
		this.configuration = configuration;
		this.init();
	}
	
	private void init(){
		this.buildConfiguration();
		this.buildView();
	}
	
	private void buildConfiguration(){
		createTitle = configuration.get("app.navigator.menuCreateTitle",createTitle);
		skinTitle = configuration.get("app.navigator.menuSkinTitle",skinTitle);
		aboutTitle = configuration.get("app.navigator.menuAboutTitle",aboutTitle);
		
		styleClass = configuration.get("app.navigator.menuStyleClass",styleClass);
		createStyleClass = configuration.get("app.navigator.menuCreateStyleClass",createStyleClass);
		skinStyleClass = configuration.get("app.navigator.menuSkinStyleClass",skinStyleClass);
		aboutStyleClass = configuration.get("app.navigator.menuAboutStyleClass",aboutStyleClass);
	}
	
	private void buildView(){
		create = new Button(createTitle);
		create.getStyleClass().addAll(createStyleClass,"menu");
		
		skin = new Button(skinTitle);
		skin.getStyleClass().addAll(skinStyleClass,"menu");
		
		about = new Button(aboutTitle);
		about.getStyleClass().addAll(aboutStyleClass,"menu");
		
		this.getChildren().addAll(create,skin,about);
		
		this.getStyleClass().add(styleClass);
	}
	
	public void setOnCreateAction(EventHandler<ActionEvent> value){
		create.setOnAction(value);
	}
	
	public void setOnSkinAction(EventHandler<ActionEvent> value){
		skin.setOnAction(value);
	}
	
	public void setOnAboutAction(EventHandler<ActionEvent> value){
		about.setOnAction(value);
	}
}
